package com.bdzl.flow.service.impl;

import com.bdzl.flow.dao.ActModelDao;
import com.bdzl.flow.service.ActModelService;
import com.bdzl.flow.servicefeign.AuthFeginService;
import com.bdzl.pub.entity.flow.ActModelDO;
import com.bdzl.pub.vo.flow.ActModelVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



@Service
public class ActModelServiceImpl implements ActModelService {
	@Autowired
	private ActModelDao actModelDao;
	@Autowired
	private AuthFeginService authFeginService;

	@Override
	public ActModelVO get(Integer actId){
		ActModelVO actModelDO = actModelDao.gets(actId);
		if (actModelDO.getActCreuser()!=null){
			Object user = authFeginService.getUserById(actModelDO.getActCreuser());
			HashMap result = (HashMap) user;
			actModelDO.setActCreuserName(String.valueOf(result.get("userNickname")));
		}
		if (actModelDO.getActModuser()!=null){
			Object user = authFeginService.getUserById(actModelDO.getActCreuser());
			HashMap result = (HashMap) user;
			actModelDO.setActModuserName(String.valueOf(result.get("userNickname")));
		}
		return actModelDO;
	}

	@Override
	public List<ActModelVO> list(Map<String, Object> map){
		List<ActModelDO> actModelDOList = actModelDao.list(map);
		List<ActModelVO> actModelVOList = new ArrayList<>();
		for (ActModelDO actModelDO : actModelDOList) {
			ActModelVO actModelVO = new ActModelVO();
			//类拷贝
			BeanUtils.copyProperties(actModelDO, actModelVO);
			if (actModelVO.getActCreuser()!=null){
				Object user = authFeginService.getUserById(actModelDO.getActCreuser());
				HashMap result = (HashMap) user;
				actModelVO.setActCreuserName(String.valueOf(result.get("userNickname")));
			}
			if (actModelDO.getActModuser()!=null){
				Object user = authFeginService.getUserById(actModelDO.getActCreuser());
				HashMap result = (HashMap) user;
				actModelVO.setActModuserName(String.valueOf(result.get("userNickname")));
			}
			actModelVOList.add(actModelVO);
		}
		return actModelVOList;
	}

	@Override
	public int count(Map<String, Object> map){
		return actModelDao.count(map);
	}

	@Override
	public int save(ActModelDO actModel){
		return actModelDao.save(actModel);
	}

	@Override
	public int update(ActModelDO actModel){
		return actModelDao.update(actModel);
	}

	@Override
	public int remove(Integer actId){
		return actModelDao.remove(actId);
	}

	@Override
	public int batchRemove(Integer[] actIds){
		return actModelDao.batchRemove(actIds);
	}

}
